<template>
	<view class="content">
		<view class="address">
			<view class="address_cont">
				<view class="address_icon">
					<image src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/addr.png" mode=""></image>
				</view>
				<view class="address_detail" v-if="yxUserAddress == null" @click="selectAddress">添加收货地址</view>
				<view class="address_detail" v-else @click="selectAddress">
					<view class="address_name">
						<view class="name">{{yxUserAddress.realName}}</view>
						<view class="phone">{{yxUserAddress.phone}}</view>
					</view>
					<view class="address_info">{{yxUserAddress.province}}{{yxUserAddress.city}}{{yxUserAddress.district}}{{yxUserAddress.detail}}</view>
				</view>
				<view class="iconfont select_icon">&#xe601;</view>
			</view>
			
		</view>
		<view class="group">
			<view class="goods">
				<view class="goods_image">
					<image :src="orderDatas.image" mode=""></image>
				</view>
				<view class="goods_cont">
					<view class="goods_name ellipsis_2">{{orderDatas.productName}}…</view>
					<view class="goods_bot">
						<view class="goods_price">
							<view class="sign iconfont">&#xe604;</view>
							<view class="price">{{orderDatas.price}}</view>
						</view>
						<view class="goods_num">X1</view>
					</view>
				</view>
			</view>
			<view class="freight">
				<view class="freight_fl">运费</view>
				<view class="freight_fr">包邮</view>
			</view>
		</view>
		
		<view class="bottom">
			<view class="submit" @click="sureOrder">确认订单</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderDatas:{},
				yxUserAddress:{},
				userAddressId:'',
				id:''
			}
		},
		onLoad(options) {
			console.log(options)
			this.id = options.id;
			this.getOrderInfo()
			let that = this;
			uni.$on('updateAddress',function(data){
				console.log('监听到事件来自 id ，携带参数 msg 为：' + data.msg);
				that.getUserAddress();
			})
			
		},
		methods: {
			getOrderInfo: function () {
				this.api.userGetPayOrder(this.id).then(res => {
					console.log(res)
					this.orderDatas = res.data;
					if (res.data.yxUserAddress != null) {
						this.yxUserAddress = res.data.yxUserAddress;
						this.userAddressId = res.data.yxUserAddress.id;
					} else {
						this.yxUserAddress = null
					}
				})
			},
			// 选择地址
			selectAddress: function () {
				uni.navigateTo({
					url: '../../user/address/address?addressType=1',
				});
			},
			// 根据地址id获取地址
			getUserAddress: function () {
				let that = this;
				that.api.getUserAddressDetail(that.userAddressId).then(res => {
					console.log(res)
					that.yxUserAddress = res.data;
				})
			},
			// 确认订单
			sureOrder: function () {
				let that = this;
				if (that.userAddressId == '') {
					that.tui.toast('请选择收货地址')
					return
				}
				that.api.auctionSureOrder({
					id:that.id,
					userAddressId:that.userAddressId
				}).then(res => {
					console.log(res)
					that.tui.toast(res.data);
					setTimeout(function () {
						uni.$emit('goTake',{msg:'页面更新'});
						uni.$emit('update',{msg:'页面更新'})
						uni.$emit('billOrder',{msg:'页面更新'})
					},500)
					setTimeout(function () {
						uni.navigateBack({
							delta: 1
						});
					},1500)
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		width: 100%;
		box-sizing: border-box;
		letter-spacing: 3rpx;
		font-family: PingFang SC;
		color: #140005;
		font-size: 28rpx;
		padding: 20rpx;
	}
	.content {
		width: 100%;
		box-sizing: border-box;
	}
	.address {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 30rpx 22rpx;
		border-radius: 12rpx;
		margin-bottom: 20rpx;
		.address_cont {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;
			color: #666666;
			.address_icon {
				width: 28rpx;
				height: 28rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.select_icon {
				width: 30rpx;
				box-sizing: border-box;
				text-align: center;
				font-size: 30rpx;
				color: #999999;
			}
			.address_detail {
				width: calc(100% - 60rpx);
				box-sizing: border-box;
				padding: 15rpx 0 15rpx 20rpx;
				.address_name {
					width: 100%;
					box-sizing: border-box;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					line-height: 60rpx;
					.name {
						padding-right: 30rpx;
					}
				}
				.address_info {
					width: 100%;
					box-sizing: border-box;
					// padding-top: 15rpx;
				}
			}
			
		}
	}
	.group {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 0 22rpx;
		.goods {
			width: 100%;
			box-sizing: border-box;
			padding: 30rpx 0;
			display: flex;
			justify-content: space-between;
			border-bottom: 2rpx solid #F5F5F5;
			.goods_image {
				width: 160rpx;
				height: 160rpx;
				image {
					width: 100%;
					height: 100%;
					border-radius: 16rpx;
				}
			}
			.goods_cont {
				width: calc(100% - 160rpx);
				box-sizing: border-box;
				padding-left: 20rpx;
				display: flex;
				flex-flow: column;
				justify-content: space-between;
				.goods_bot {
					width: 100%;
					box-sizing: border-box;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 22rpx;
					color: #212121;
					.goods_price {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						color: #E42221;
						.price {
							font-size: 28rpx;
						}
					}
				}
				.goods_name {
					width: 100%;
					box-sizing: border-box;
					line-height: 40rpx;
				}
			}
		}
		.freight {
			width: 100%;
			box-sizing: border-box;
			line-height: 100rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
	.bottom {
		width: 100%;
		box-sizing: border-box;
		padding: 130rpx 50rpx 0 50rpx;
		.submit {
			width: 100%;
			box-sizing: border-box;
			text-align: center;
			font-size: 30rpx;
			color: #FFFFFF;
			background: #E42221;
			border-radius: 8rpx;
			line-height: 94rpx;
		}
	}

</style>
